package cn.iocoder.yudao.module.blog.controller.admin.jiucaselevel;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.blog.controller.admin.jiucaselevel.vo.*;
import cn.iocoder.yudao.module.blog.dal.dataobject.jiucaselevel.BlogJiuCaseLevelDO;
import cn.iocoder.yudao.module.blog.convert.jiucaselevel.BlogJiuCaseLevelConvert;
import cn.iocoder.yudao.module.blog.service.jiucaselevel.BlogJiuCaseLevelService;

@Tag(name = "管理后台 - 灸法案例审批等级")
@RestController
@RequestMapping("/blog/jiu-case-level")
@Validated
public class BlogJiuCaseLevelController {

    @Resource
    private BlogJiuCaseLevelService jiuCaseLevelService;

    @PostMapping("/create")
    @Operation(summary = "创建灸法案例审批等级")
    @PreAuthorize("@ss.hasPermission('blog:jiu-case-level:create')")
    public CommonResult<Long> createJiuCaseLevel(@Valid @RequestBody BlogJiuCaseLevelCreateReqVO createReqVO) {
        return success(jiuCaseLevelService.createJiuCaseLevel(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新灸法案例审批等级")
    @PreAuthorize("@ss.hasPermission('blog:jiu-case-level:update')")
    public CommonResult<Boolean> updateJiuCaseLevel(@Valid @RequestBody BlogJiuCaseLevelUpdateReqVO updateReqVO) {
        jiuCaseLevelService.updateJiuCaseLevel(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除灸法案例审批等级")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('blog:jiu-case-level:delete')")
    public CommonResult<Boolean> deleteJiuCaseLevel(@RequestParam("id") Long id) {
        jiuCaseLevelService.deleteJiuCaseLevel(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得灸法案例审批等级")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('blog:jiu-case-level:query')")
    public CommonResult<BlogJiuCaseLevelRespVO> getJiuCaseLevel(@RequestParam("id") Long id) {
        BlogJiuCaseLevelDO jiuCaseLevel = jiuCaseLevelService.getJiuCaseLevel(id);
        return success(BlogJiuCaseLevelConvert.INSTANCE.convert(jiuCaseLevel));
    }

    @GetMapping("/list")
    @Operation(summary = "获得灸法案例审批等级列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('blog:jiu-case-level:query')")
    public CommonResult<List<BlogJiuCaseLevelRespVO>> getJiuCaseLevelList(@RequestParam("ids") Collection<Long> ids) {
        List<BlogJiuCaseLevelDO> list = jiuCaseLevelService.getJiuCaseLevelList(ids);
        return success(BlogJiuCaseLevelConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得灸法案例审批等级分页")
    @PreAuthorize("@ss.hasPermission('blog:jiu-case-level:query')")
    public CommonResult<PageResult<BlogJiuCaseLevelRespVO>> getJiuCaseLevelPage(@Valid BlogJiuCaseLevelPageReqVO pageVO) {
        PageResult<BlogJiuCaseLevelDO> pageResult = jiuCaseLevelService.getJiuCaseLevelPage(pageVO);
        return success(BlogJiuCaseLevelConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出灸法案例审批等级 Excel")
    @PreAuthorize("@ss.hasPermission('blog:jiu-case-level:export')")
    @OperateLog(type = EXPORT)
    public void exportJiuCaseLevelExcel(@Valid BlogJiuCaseLevelExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<BlogJiuCaseLevelDO> list = jiuCaseLevelService.getJiuCaseLevelList(exportReqVO);
        // 导出 Excel
        List<BlogJiuCaseLevelExcelVO> datas = BlogJiuCaseLevelConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "灸法案例审批等级.xls", "数据", BlogJiuCaseLevelExcelVO.class, datas);
    }

}
